home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
ms_dos
/
nifp
/
nifplog.c
< prev
next >
Wrap
Text File
|
1993-07-08
|
50KB
|
2,231 lines
/*
* このモジュールは,NIFPのタイトル区分処理部です。主にログファイルを読み込んで,
* タイトルテーブルを作成します。
* このモジュールは,マシン依存していません。
*/
#include "nifp.h"
char hpid[9],hpmsg[63],forummsg[81],forumname[20],savebuf[81];
char mestno[20][81];
char libtno[20][81];
char niftyid[9];
char profid[9];
char patioid[9];
int fmeslibno=0,forumon=0;
int titlecountr=0;
char far *po;
int gp=0;
int pend=0;
char heya[3],saveheya[3];
long jpp=0,jpplno=0,savepp=0,savepplno=0,fsavepp=0;
long xxp=0,xxplno=0;
int jumpon=0,submode=0,linecount=0,preno=0;
long forum3msgp=0,forum3lno=0;
static FILE *nifoutfd;
static FILE *nifoutfd2;
static char nifoutfname[140];
static char nifoutfname1[129];
static char nifoutfname2[129];
char *initial="<< オープニング メッセージ >> ";
char *dataend=" << データの終わり >>";
char *spalate=" ------------------------------------- ";
char *newstitle="<< ニュース >>";
char *sinbuntitle="<< ニュース速報 >>";
char *etctitle="<< その他 >>";
char *mailtitle="<< 電子メール >> ";
char *hptitle="<< ホームパーティ >>";
char *forumtitle="<< フォーラム >>";
char *forum2title="会議室";
char *bbstitle="<< 掲示板 >>";
char *notetitle="<< お知らせ >>";
char *billtitle="<< 課金情報 >> ";
char *cbtitle="<< CB >>";
char *byetitle="<< ログオフ >> ";
char *toptitle="<< トップメニュー >>";
char *membertitle="<< 会員情報 >>";
char *infotitle="<< 情報サービス >>";
char *tenkititle="<< 天気予報 >>";
char *writetitle="## 発言 ## ";
char *guesttitle="## ゲスト情報 ##";
char *titlehptitle="<タイトル一覧>";
char *mrcvtitle="## 受信一覧 ##";
char *sdltitle="## 送信簿 ##";
char *rcltitle="## 受信簿 ##";
char *myforumtitle="<入会フォーラム一覧>";
static int cutsub(char *buf)
{
int i;
char buf1[81];
for(i=0;i < MAXCUTNO && cutstrtbl[i];i++) {
_fstrcpy((char far *)buf1,cutstrtbl[i]);
if(!xstrncmp(buf,&buf1[1])) {
if(buf1[0] == '1') return(1);
else return(2);
}
}
return(0);
}
int bunget(PCELL far *tcu, int mode) /* 内容表示用読み込み */
{
char c,buf[81],buf2[81],savec = 0;
int i=0,j,m,k,savemore = 0;
long nl;
tbl_set(tcu);
xxfseek(tcu,tcu->p->top);
nl = tcu->p->tail;
if(xftell() == nl) return(0);
for(k = 1;k < MAXLINE;k++) {
if(xftell() >= nl && nl) break;
if(savec) {
savec = 0;
for(j=0;j < 80-i && (c = buf[i+j]);j++) {
buf[j] = c;
if(c == '\n') {
buf[++j] = 0;
break;
}
}
if(buf[j-1] != '\n') {
if(!xfgets(&buf[j],81-j)) break;
}
}
else if(!xfgets(buf,81)) break;
for(i = j = 0,m = 1;(c = buf[i]);i++) {
if(c == '\b') {
if(m > 1) {
j--;
m--;
}
continue;
}
if(m > 80) {
savec = 1;
break;
}
if(iskanji(c)) {
if(m >= 80) {
savec = 1;
break;
}
buf2[j++] = c;
buf2[j++] = buf[++i];
m++; m++;
continue;
}
buf2[j++] = c;
m++;
if(mode && c == '\t') {
for(;(m-1)%(tabno);) m++;
if(m >= 80) {
savec = 1;
i++;
break;
}
continue;
}
if(c == '\n') break;
}
if(xfeof() && c != '\n') buf2[j++] = '\n';
buf2[j] = 0;
if(cutmode) {
if(savemore) {
savemore = 0;
if(!xstrncmp(buf2,">") || !xstrncmp(buf2,":")) {
k--;
farfree(buf1[k-1]);
buf1[k-1] = 0;
k--;
continue;
}
}
else {
switch(cutsub(buf2)) {
case 1: k--; continue;
case 2: savemore = 1;
}
}
}
buf1[k-1] = (char far *)farmalloc((long)strlen(buf2)+1);
if(!buf1[k-1]) {
errdisp1(memgeterror);
break;
}
_fstrcpy(buf1[k-1],(char far *)buf2);
}
if(savemore) {
k--;
farfree(buf1[k-1]);
buf1[k-1] = 0;
}
if(cutmode == 3) {
_fstrcpy((char far *)buf2,buf1[k-2]);
if((!xstrncmp(buf2,"- ") && strstr(buf2,"MES("))
|| !xstrncmp(buf2,"-会議室")) {
farfree(buf1[k-2]);
buf1[k-2] = 0;
k--;
}
}
if(mode && cutmode >= 2) {
for(;k > 2;k--) {
if(buf1[k-2][0] == '\n') {
farfree(buf1[k-2]);
buf1[k-2] = 0;
}
else break;
}
}
return(k);
}
static int bytedec(char *a) {
int i=0;
if(!isdigit(a[0])) {
if(a[0] != ' ') return(i);
}
else i = (int)(a[0] - '0');
if(isdigit(a[1]))
i = i * 10 + (int)(a[1] - '0');
return(i);
}
void str79set(char *buf)
{
if(strlen(buf) >= 79) {
if(nthctype(buf,78) == CT_KJ1) buf[78] = 0;
else buf[79] = 0;
}
}
static int
setpoint(char mode,long grp,char *buf) /* タイトルテーブル作成 */
{
PCELL far *pt;
PCELL far *w;
if(sepamode && mode == NSEPA)
return(0);
str79set(buf);
pt = tbl_alloc(0);
if(!pt) {
errdisp3(memgeterror);
return(-1);
}
tbl_set(pt);
pt->mode = mode;
pt->count = p+1;
pt->p->lineno = xxplno+1;
pt->p->fno = cfno;
pt->p->top = xxp;
if(mode == NEND) pt->p->tail = xxp;
tbl_set(p_tail);
if(p && p_tail->p->fno == cfno) p_tail->p->tail = xxp;
if(p == grp) pt->grp = pt;
else {
for(w=p_tail;w;w=w->back) {
if(w->count != grp+1) continue;
pt->grp = w;
break;
}
}
tbl_set(pt);
_fstrcpy(pt->p->title,(char far *)buf);
if(strlen(niftyid)) _fmemcpy(pt->p->nifid,niftyid,8);
else _fstrcpy(pt->p->nifid,"ID");
if(!p_tail) {
p_top = p_head = p_tail = pt;
}
else {
p_tail->next = pt;
pt->back = p_tail;
p_tail = pt;
}
p++;
xnstatus();
linecount=1;
jumpon = 0;
if(titlecountr > 0)
titlecountr--;
switch(mode) {
case NTOP:
case NNEWSHEAD:
case NBBSHEAD:
case NCBHEAD:
case NNOTEHEAD:
case NMEMBERHEAD:
case NINFOHEAD:
case NETC:
forumon = 0;
break;
case NFORUMHEAD:
case NPATIOHEAD:
forumon = 1;
break;
case NMAILHEAD:
forumon = 2;
break;
}
return(0);
}
static int setpoint2(char mode,char *buf) /* タイトルテーブル作成 */
{
return(setpoint(mode,p,buf));
}
static int setpoint3(char mode,char *buf) /* タイトルテーブル作成 */
{
return(setpoint(mode,gp,buf));
}
static int setpoint4(char mode,char *buf) /* 同じタイトルは出力しない */
{
if(!p_tail || p_tail->mode != mode)
return(setpoint(mode,p,buf));
return(0);
}
static void nifidsetsub(char *work)
{
tbl_set(p_tail);
_fmemcpy(p_tail->p->nifid,(char far *)work,8);
}
static void nifidset(char *buf) /* フォーラム名セット */
{
char work[9];
tbl_set(p_tail);
p_tail->p->cno = fmeslibno;
if(strlen(buf)) {
xxstrncpy(work,buf,8);
nifidsetsub(work);
}
else nifidsetsub("FORUM");
}
static int hpout(void) /* HP出力 */
{
char msg[128];
sprintf(msg," ☆ HP %s:%s",hpid,hpmsg);
if(setpoint2(NHPHEAD,msg)) return(1);
nmode=NHP;
if(!strlen(hpid)) strcpy(hpid,"HP");
nifidset(hpid);
hpid[0] = 0;
preno = 0;
return(0);
}
static int patioout(void) /* パティオ出力 */
{
char msg[128];
sprintf(msg," ☆ パティオ :%s",patioid);
if(setpoint2(NPATIOHEAD,msg)) return(1);
strcpy(forumname,patioid);
nmode=NPATIO;
nifidset(patioid);
patioid[0] = 0;
preno = 0;
return(0);
}
static int heyaout(void) /* 会議室出力 */
{
char *a,buf[81];
long savexp,savexplno,xp;
if(strlen(forummsg)) {
if(a = strrchr(forummsg,' ')) {
a++;
xxstrncpy(forumname,a,19);
}
if(setpoint2(NFORUMHEAD,forummsg)) return(1);
nifidset(forumname);
if(forum3msgp) {
savexp = xxp;
savexplno = xxplno;
xxp = forum3msgp;
xxplno = forum3lno;
xp = xftell();
xfseek(forum3msgp);
xfgets(buf,81);
rtncut(buf);
xfseek(xp);
if(setpoint3(NFORUM2,buf)) return(1);
nifidset(forumname);
xxp = savexp;
xxplno = savexplno;
forum3msgp = 0;
}
nmode=NFORUM;
forummsg[0] = 0;
}
memset(saveheya,0,3);
return(0);
}
static int libnoout(void) /* データライブラリ出力 */
{
char msg[81];
sprintf(msg,"- %s LIB(%2d):%s",forumname,fmeslibno,libtno[fmeslibno-1]);
if(setpoint2(NLIBHEAD,msg)) return(1);
nifidset(forumname);
nmode=NLIBNO;
return(0);
}
static char *logck_1[] = {
"MEMBER",
"MAIL",
"BBS",
"BOARD",
"MYFORUM",
"CB",
"HELLO",
"TOP",
"T",
"TT",
"NIF",
"FORUM",
"OFF",
"BYE",
"LOG",
(char *)0
};
static char *logck_2[] = {
"COM",
"COMP",
"WRITE",
"SAY",
"ANN",
"BUL",
"RTC",
"OPT",
"E"
"?",
"MEM",
"RVL",
"SDL",
(char *)0
};
static char *logck2_1[] = {
"LIB",
"MES",
"CCS(",
"PATIO(",
"RX",
"DL",
"DIR",
"HELP",
"UST",
(char *)0
};
static int logcheck1(char *buf,char *ck[])
{
char *s,*d;
int i;
for(i=0;ck[i];i++) {
s = buf;
d = ck[i];
while(*s == *d) {
if(!*d) return(0);
s++;
d++;
}
}
return(1);
}
static int logcheck2(char *buf,char *ck[])
{
char *s,*d;
int i;
for(i=0;d=ck[i];i++) {
s = buf;
while(*s == *d) {
if(!*d) return(0);
s++;
d++;
if(!*d) return(0);
}
}
return(1);
}
static int jumpcheck(char *buf) /* ジャンプコマンド検出 */
{
int i,j;
char *a,b[81],c;
long xp;
if(!xstrncmp(buf,"ID (改行の")) {
hpmsg[0] = 0;
strcpy(hpid,niftyid);
return(1);
}
if(!xstrncmp(buf,"ID(改行で終了)")) {
xp = xftell();
if(!xfgets(b,81)) return(0);
rtncut(b);
xfseek(xp);
if(!xstrncmp(b,":") && isascii(b[2]) && isdigit(b[9])) {
xxstrncpy(profid,&b[2],8);
submode = SPROF;
}
return(0);
}
if(!xstrncmp(buf,"---/ ") && strstr(buf,"/---------")) {
if(isascii(buf[5]) && isdigit(buf[8])) {
xxstrncpy(niftyid,&buf[5],8);
}
return(3);
}
if(!xstrncmp(buf,">")) {
a = &buf[2];
}
else if(*buf == '>') {
a = &buf[1];
}
else if(((c=buf[0]) >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
c = buf[10];
buf[10] = 0;
a = strchr(buf,'>');
buf[10] = c;
if(a) a++;
else return(0);
}
else return(0);
if(!*a || iskanji(*a)) return(0);
for(i = j = 0; a[i] != 0; i++) {
if(a[i] == '\t') b[j++] = ' ';
else b[j++] = toupper(a[i]);
}
b[j] = 0;
if(!xstrncmp(b,"LIB ")) a = &b[4];
else if(!xstrncmp(b,"DL ") || !xstrncmp(b,"RX ")) a = &b[3];
else if(!xstrncmp(b,"MES ")) a = &b[4];
else if(!xstrncmp(buf,">") && !fmeslibno) {
a = &b[0];
}
else a = buf;
if(a != buf) {
if(i = bytedec(a))
fmeslibno = i;
}
if(i = bytedec(b) && strlen(b) <= 2)
return(1);
if(!xstrncmp(buf,"HP>")) {
submode = 0;
passflag = 0;
}
if(!xstrncmp(buf,"MAIL>")) {
passflag = 0;
}
if(!xstrncmp(b,"GO "))
return(2);
if(!logcheck1(b,logck_1))
return(2);
if(!xstrncmp(b,"MOV")) {
if(strlen(b) > 8) {
if(b[3] == 'E') a = &b[5];
else a = &b[4];
hpmsg[0] = 0;
xxstrncpy(hpid,a,8);
}
return(2);
}
if(!xstrncmp(buf,"HP>GUE")) {
submode = SGUEST;
passflag = 0;
return(0);
}
if(!xstrncmp(buf,"HP>TIT")) {
submode = STITLE;
passflag = 0;
return(0);
}
if(!xstrncmp(buf,">GUE"))
return(3);
if(!forumon && (!xstrncmp(b,"SMAIL") || !xstrncmp(b,"SENDMAIL"))) {
forumon = 2;
return(2);
}
if(!xstrncmp(buf,">OPT") || !logcheck1(b,logck_2)
|| !logcheck2(b,logck2_1))
return(1);
if(!xstrncmp(b,"PROF ") && isascii(b[5]) && isdigit(b[8]) && !b[13]) {
xxstrncpy(profid,&b[5],8);
submode = SPROF;
}
return(0);
}
static void meslibclr(char *buf)
{
int i;
for(i = 0;i < 20; i++)
mestno[i][0] = libtno[i][0] = 0;
fmeslibno = 0;
xxstrncpy80(forummsg,buf);
}
static int stagecheck(char *buf) /* フェーズ切り換え行検出 */
{
char *a,buf1[81];
int i;
if(iskanji(*buf)) {
if(!xstrncmp(buf," "))
return(0);
if(!xstrncmp(buf,"オプション (1:"))
return(NOPT);
if(!xstrncmp(buf,"<タイトル一") || !xstrncmp(buf,"<メッセージタイ"))
return(NFRT);
if(!xstrncmp(buf,"<発言検索"))
return(NFRS);
if(!xstrncmp(buf,"番号 発言 (未"))
return(NMES);
if(!xstrncmp(buf,"開始番号 (改行"))
return(NMEMBER);
if(!xstrncmp(buf,"項目(改行のみ"))
return(NETC);
if(!xstrncmp(buf,"番号 総数 登録"))
if((!p_tail || p_tail->mode != NFORUM) || jumpon)
return(NLIB);
if(!xstrncmp(buf,"番号 ID")) {
if((!p_tail || p_tail->mode != NFORUM) || jumpon)
return(NLIBNO);
return(0);
}
if(!xstrncmp(buf,"ようこそNIFTY")
|| !xstrncmp(buf,"前回LOG O")) {
return(NINIT);
}
if(!xstrncmp(buf,"ニュース速報") || !xstrncmp(buf,"☆フラッシュ")
|| !xstrncmp(buf,"☆共同金融経")) {
return(NSINBUN);
}
if(!xstrncmp(buf,"番号 登録者") || !xstrncmp(buf,"掲示板 BBS")) {
if(forumon != 1) return(NBBS);
return(NFBBS);
}
if(!xstrncmp(buf,"電子メール(1:"))
return(NMAIL);
if(!xstrncmp(buf,"番号 提供日")
|| !xstrncmp(buf,"オンライン・ト")) {
if(forumon != 1) return(NNOTE);
return(NFNEWS);
}
if(!xstrcmp(buf,"今週のお知らせ NEW"))
return(NNEWS);
if(!xstrncmp(buf,"FM情報サ") || !xstrncmp(buf,"** 情報センター ")) {
meslibclr(buf);
return(NFORUM);
}
if(!xstrncmp(buf,"課金情報 (1:") || !xstrncmp(buf,"課金情報 B")
|| !xstrncmp(buf,"年/月 回数 時"))
return(NBILL);
if(!xstrncmp(buf,"ハンドルネームとタ")) {
return(NHPWRITE);
}
if(!xstrncmp(buf,"本文(300 行") || !xstrncmp(buf,"本文 (300行")) {
if(forumon == 1) return(NFWRITE);
if(forumon == 2) return(NMWRITE);
return(NWRITE);
}
if(!xstrncmp(buf,"-リアルタイム")) {
passflag = 1;
return(NFRTIME);
}
if(!xstrncmp(buf,"会員情報(1:パス"))
return(NMEMBER);
if(!xstrcmp(buf,"番号 題名"))
return(NINFO);
if(strstr(buf," W")) {
if(!xstrncmp(buf,"天気予報") || !xstrncmp(buf,"おでかけ天")
|| !xstrncmp(buf,"全国都市予報") || !xstrncmp(buf,"ゴルフ天")
|| !xstrncmp(buf,"海釣り天")
|| !xstrncmp(buf,"ウィンドサーフィン天")
|| !xstrncmp(buf,"世界の都市予報"))
return(NTENKI);
}
if(!xstrncmp(buf,"番号 送信者"))
return(NMRCV);
if(!xstrncmp(buf,"送信日 受信"))
return(NSDL);
if(!xstrncmp(buf,"受信日 送信"))
return(NRCL);
if(!xstrncmp(buf,"アクセス・ギ"))
return(NETC);
if(!xstrncmp(buf,"貴方は以下のフォーラム"))
return(NMYFORUM);
if(!xstrncmp(buf,":") && strlen(buf) == 10
&& isalpha(buf[2]) && isdigit(buf[5])
&& !xstrncmp(savebuf,"ID (改行のみ:自分のパティオ")) {
xxstrncpy(patioid,&buf[2],8);
return(NPATIO);
}
if(!xstrncmp(buf,">GUE")) {
return(NPGUEST);
}
for(i=0;i < MAXMSGNO && msgstrtbl[i];i++) {
_fstrcpy((char far *)buf1,msgstrtbl[i]);
if(!xstrncmp(buf,&buf1[1])) {
if(!forum3msgp) {
forum3msgp = xxp;
forum3lno = xxplno;
}
}
}
}
else {
if(!xstrncmp(buf," # Total#(unr"))
return(NMES);
if(!xstrncmp(buf," Enter User")) {
memset(niftyid,0,9);
if(a = strchr(buf,'>'))
strncpy(niftyid,&a[1],8);
return(NINIT);
}
if(!xstrncmp(buf,"Welcome to NIF"))
return(NINIT);
if(!xstrncmp(buf,"NIFTY-Serve TOP")
|| !xstrncmp(buf,"NIFTY-Serve ES TOP")) {
return(NTOP);
}
if(!xstrncmp(buf,"MAIL>") || !xstrncmp(buf,"Mail (1:")) {
return(NMAIL);
}
if(!xstrncmp(buf,"NEWS>"))
return(NNEWS);
if(!xstrncmp(buf,"1:お知ら") || !xstrncmp(buf,"*:お知ら")
|| !xstrncmp(buf,"1:フォーラム概")) {
if(!xstrncmp(savebuf,"<") || *savebuf == '<') {
meslibclr(savebuf);
return(NFORUM);
}
}
if(!xstrncmp(buf,"FORUM>") || !xstrncmp(buf,"1:Announcements")) {
if(!xstrncmp(savebuf,"<") || *savebuf == '<') {
meslibclr(savebuf);
return(NFORUM);
}
}
if(!xstrncmp(buf," ☆ HP ")) {
xxstrncpy(hpmsg,&buf[18],62);
xxstrncpy(hpid,&buf[9],8);
return(NHP);
}
if(!xstrncmp(buf," ☆ パティオ ")) {
xxstrncpy(patioid,&buf[14],8);
return(NPATIO);
}
if(!xstrncmp(buf,"BILL>"))
return(NBILL);
if(!xstrncmp(buf,"CBシミュレ") || !xstrncmp(buf,"CB>")
|| !xstrncmp(buf,"*Welcome to CB")) {
passflag = 1;
return(NCB);
}
if(!xstrncmp(buf," LOG IN "))
return(NBYE);
if(!xstrncmp(buf,"HP>")) {
if(!strlen(hpmsg))
xxstrncpy(hpmsg,savebuf,62);
return(NHP);
}
if(!xstrncmp(buf,"ID Name ("))
return(NMEMBER);
if(!xstrncmp(buf,"---/ Sent "))
return(NM2WRITE);
}
return(0);
}
static int stageset(int smode,long xp,long xplno) /* タイトル出力 */
{
char msg[81];
int i;
long savexp,savexplno;
savexp = xxp;
savexplno = xxplno;
xxp = xp;
xxplno = xplno;
switch(smode) {
case NINIT:
strcpy(msg,initial);
if(strlen(niftyid))
strcat(msg,niftyid);
if(setpoint4(NINIT,msg)) return(1);
break;
case NTOP:
if(setpoint4(NTOP,toptitle)) return(1);
break;
case NBBS:
if(setpoint4(NBBSHEAD,bbstitle)) return(1);
break;
case NNEWS:
if(setpoint4(NNEWSHEAD,newstitle)) return(1);
break;
case NFBBS:
sprintf(msg,"- %s BBS:掲示版",forumname);
if(setpoint2(NFBBSHEAD,msg)) return(1);
stage_00:
nifidset(forumname);
break;
case NFNEWS:
sprintf(msg,"- %s NEWS:お知らせ",forumname);
if(setpoint2(NFNEWSHEAD,msg)) return(1);
goto stage_00;
case NNOTE:
if(setpoint4(NNOTEHEAD,notetitle)) return(1);
break;
case NSINBUN:
if(setpoint4(NSINBUNHEAD,sinbuntitle)) return(1);
break;
case NMAIL:
strcpy(msg,mailtitle);
strcat(msg,niftyid);
if(setpoint4(NMAILHEAD,msg)) return(1);
break;
case NHP:
if(hpout()) return(1);
break;
case NPATIO:
if(patioout()) return(1);
break;
case NFORUM:
if(heyaout()) return(1);
break;
case NBILL:
strcpy(msg,billtitle);
strcat(msg,niftyid);
if(setpoint2(NBILLHEAD,msg)) return(1);
break;
case NCB:
if(setpoint2(NCBHEAD,cbtitle)) return(1);
break;
case NMEMBER:
if(setpoint4(NMEMBERHEAD,membertitle)) return(1);
break;
case NMES:
sprintf(msg,"# %s MES < 会議室 >",forumname);
for(i = 0;i < 20; i++)
mestno[i][0] = 0;
fmeslibno = 0;
if(setpoint2(NMESNOHEAD,msg)) return(1);
goto stage_00;
case NLIB:
sprintf(msg,"# %s LIB < データライブラリ >",forumname);
for(i = 0;i < 20; i++)
libtno[i][0] = 0;
fmeslibno = 0;
if(setpoint2(NLIBNOHEAD,msg)) return(1);
goto stage_00;
case NBYE:
strcpy(msg,byetitle);
strcat(msg,niftyid);
if(setpoint4(NBYEHEAD,msg)) return(1);
memset(niftyid,0,9);
break;
case NFRT:
sprintf(msg,"- %s MES(%2d) < タイトル一覧 >",forumname,fmeslibno);
if(setpoint2(NFRTHEAD,msg)) return(1);
goto stage_00;
case NFRS:
sprintf(msg,"- %s MES(%2d) < 発言検索 >",forumname,fmeslibno);
if(setpoint2(NFRSHEAD,msg)) return(1);
goto stage_00;
case NLIBNO:
libnoout();
break;
case NFRTIME:
sprintf(msg,"- %s RTC:リアルタイム会議",forumname);
if(setpoint2(NFRTIMEHEAD,msg)) return(1);
goto stage_00;
case NINFO:
if(setpoint4(NINFOHEAD,infotitle)) return(1);
break;
case NTENKI:
if(setpoint4(NTENKI,tenkititle)) return(1);
break;
case NMRCV:
if(setpoint2(NMRCVHEAD,mrcvtitle)) return(1);
break;
case NSDL:
if(setpoint2(NSDLHEAD,sdltitle)) return(1);
break;
case NRCL:
if(setpoint2(NRCLHEAD,rcltitle)) return(1);
break;
case NMYFORUM:
if(setpoint2(NMYFORUM,myforumtitle)) return(1);
break;
case NOPT:
sprintf(msg,"- %s OPT:オプション設定",forumname);
if(setpoint4(NOPTHEAD,msg)) return(1);
goto stage_00;
default:
if(setpoint2(NETC,etctitle)) return(1);
break;
}
xxp = savexp;
xxplno = savexplno;
return(0);
}
static int heyasepa(void) /* 会議室区切り出力 */
{
char msg[81],*a;
int i;
long savexp,savexplno;
savexp = xxp;
savexplno = xxplno;
xxp = savepp;
xxplno = savepplno;
strcpy(msg,savebuf);
if(!xstrncmp(savebuf,"- MES(")) { /* "- MES(xx) ・・・・" */
if(strlen(forumname)) {
sprintf(msg,"- %s ",forumname);
strncat80(msg,&savebuf[1]);
}
fmeslibno = bytedec(&savebuf[6]);
}
else if(!xstrncmp(savebuf,"-room# : ")) { /* "-room# : xx・・・" */
if(strlen(forumname)) {
sprintf(msg,"- %s MES(",forumname);
strncat80(msg,&savebuf[9]);
}
fmeslibno = bytedec(&savebuf[9]);
}
else if(!xstrncmp(savebuf,"- ") || !xstrncmp(savebuf,"<< 会議")) {
if(a=strchr(savebuf,'('))
fmeslibno = bytedec(a+1);
}
else if(!xstrncmp(savebuf,"-会議室")) {
if(strlen(forumname)) {
sprintf(msg,"- %s MES(%c%c):",forumname,savebuf[8],savebuf[9]);
strncat80(msg,&savebuf[12]);
}
fmeslibno = bytedec(&savebuf[8]);
}
else {
if(i=bytedec(heya))
fmeslibno = i;
sprintf(msg,"- %s MES(%2d):%s",forumname,fmeslibno,mestno[fmeslibno-1]);
xxp = savexp;
xxplno = savexplno;
}
if(setpoint2(NMESHEAD,msg)) return(1);
nifidset(forumname);
xxp = savexp;
xxplno = savexplno;
nmode = NFORUM;
return(0);
}
static int headcheck(char mode)
{
long xp,xplno;
if(nmode != mode) {
gp = p;
xp = xxp;
xplno = xxplno;
if(jumpon) {
xp = jpp;
xplno = jpplno;
jumpon = 0;
}
if(stageset(mode,xp,xplno)) return(1);
nmode = mode;
}
if(jumpon) jumpon = 0;
return(0);
}
char savehpread=0;
static int lineread(char *buf) /* 一行読み込み */
{
memset(buf,0,81);
if(savehpread) {
buf[0] = savehpread;
savehpread = 0;
if(!xfgets(&buf[1],80)) return(1);
}
else if(!xfgets(buf,81)) return(1);
if(strlen(buf) == 80 && nthctype(buf,79) == CT_KJ1) {
savehpread = buf[79];
buf[79] = 0;
}
if(!rtncut(buf))
p_linecount--;
return(0);
}
static int ckhpsub(char *buf,int mode)
{
long xp;
char buf3[81];
int i;
xp = xftell();
if(!xfgets(buf3,81)) return(-2);
i = rtncut(buf3);
if(strlen(buf3)) {
xfseek(xp);
return(1);
}
if(i) p_linecount++;
if(headcheck(mode) || setpoint3(mode,buf)) return(-1);
nifidsetsub(&buf[6]);
return(1);
}
static int checklib(char *buf) /* データライブラリチェック */
{
if(p_tail && p_tail->mode == NFORUM && !jumpon)
return(0);
if(!xstrncmp(buf,"データ名:"))
return(1);
if(isdigit(buf[3]) && buf[4] == ' ' && buf[5] == ' '
&& isdigit(buf[9]) && isdigit(buf[13]) && buf[23] == 'B'
&& buf[24] == 'y' && buf[25] == 't') /* ブラウザ機能 */
return(1);
return(0);
}
static int checkhpsub(char *buf) /* タイトル検出サブ */
{
long xp,wp;
char buf3[81],*a;
int i,j;
if(!xstrncmp(buf,"-会議室") && strncmp(&buf[8],&saveheya[0],2)) {
gp = p;
if(!strlen(forumname))
strcpy(buf3,buf);
else {
sprintf(buf3,"- %s MES(%c%c):",forumname,buf[8],buf[9]);
strncat80(buf3,&buf[12]);
}
fmeslibno = bytedec(&buf[8]);
if(setpoint2(NMESHEAD,buf3)) return(-1);
nifidset(forumname);
nmode = NFORUM;
memcpy(saveheya,&buf[8],2);
return(2);
}
if(p_tail && p_tail->mode == NFORUM && !jumpon)
return(0);
if(buf[0] == '-' && (a = strstr(buf," LIB("))) {
a -= 2;
if(i = bytedec(a))
fmeslibno = i;
gp = p;
if(setpoint2(NLIBHEAD,buf)) return(-1);
nifidset(forumname);
nmode = NLIBNO;
return(2);
}
if(checklib(buf)) {
if(headcheck(NLIBNO) || setpoint3(NLIBDATA,buf))
return(-1);
return(1);
}
if(iskanji(buf[0])) {
if(!xstrncmp(buf,":") && strlen(buf) == 10
&& isalpha(buf[2]) && isdigit(buf[5])) {
hpmsg[0] = 0;
xxstrncpy(hpid,&buf[2],8);
return(1);
}
if(!xstrcmp(buf,":") && !xstrcmp(savebuf,"パスワード")) {
wp = xftell();
if(lineread(buf3)) return(-2);
xfseek(wp);
xxstrncpy(hpmsg,buf3,62);
return(1);
}
return(0);
}
if(!xstrncmp(buf,"---/ ") && strstr(buf,"/-----/") /* air craft 対応 */
&& isascii(buf[5]) && isdigit(buf[8])) {
if(lineread(buf)) return(-2);
p_linecount++;
}
if(buf[2] == ' ' && buf[34] == '/' /* 電子メールチェック */
&& buf[40] == ':'&& isdigit(buf[1])
&& isdigit(buf[32]) && isdigit(buf[33])) {
if(headcheck(NMAIL)) return(-1);
wp = xftell();
if(lineread(buf3)) return(-2);
xfseek(wp);
strcat(buf," ");
strncat80(buf,&buf3[10]);
if(setpoint3(NMAIL,buf)) return(-1);
if(buf[0] != ' ') i = (buf[0]-'0') * 10;
else i = 0;
i += buf[1]-'0';
tbl_set(p_tail);
p_tail->p->id = i;
nifidsetsub(&buf[22]);
/* passflag = 1; */
return(2);
}
if(buf[3] == ' ' && buf[5] == ' ' /* 掲示板チェック */
&& buf[15] == ' ' && isdigit(buf[2]) && buf[28] == ' '
&& isdigit(buf[19]) && isdigit(buf[20]) && buf[18] == '/'
&& isdigit(buf[27])) {
xp = xftell();
if(!xfgets(buf3,81)) return(-2);
j = rtncut(buf3);
if(strlen(buf3) >= 2 && buf3[2] != ' ' && xstrncmp(buf3," ")) {
xfseek(xp);
return(0);
}
if(j) p_linecount++;
if(forumon != 1) i = NBBS;
else i = NFBBS;
if(headcheck(i) || setpoint3(i,buf))
return(-1);
if(buf[0] != ' ') i = (buf[0]-'0') * 10;
else i = 0;
if(buf[1] != ' ') i = (i+buf[1]-'0') * 10;
i += buf[2]-'0';
tbl_set(p_tail);
p_tail->p->id = i;
_fmemcpy(p_tail->p->nifid,(char far *)&buf[6],8);
return(1);
}
if(buf[4] == ' ' && buf[5] == ' ' /* お知らせチェック */
&& buf[8] == '/' && buf[11] == '/'
&& isdigit(buf[3]) && isdigit(buf[6]) && isdigit(buf[7])) {
return(ckhpsub(buf,NNEWS));
}
if(buf[3] == ' ' && buf[4] == ' ' /* オンライン・ツゥディチェック */
&& buf[5] == ' ' && buf[8] == '/' && buf[11] == '/'
&& isdigit(buf[2]) && isdigit(buf[6]) && isdigit(buf[7])) {
if(forumon != 1) i = NNOTE;
else i = NFNEWS;
return(ckhpsub(buf,i));
}
if(isdigit(buf[2]) && buf[3] == ' ' /* 新聞情報チェック */
&& buf[4] == ' ' && buf[5] == ' '
&& isdigit(buf[7]) && buf[8] == '/'
&& isdigit(buf[13]) && buf[14] == ':') {
return(ckhpsub(buf,NSINBUN));
}
if(nmode == NMES) {
if(isdigit(buf[1]) && buf[2] == ' ' && buf[11] == '('
&& buf[16] == ')' && buf[22] == '/') {
i = bytedec(buf);
strcpy(mestno[i-1],&buf[28]);
}
}
if(nmode == NLIB) {
if(isdigit(buf[3]) && buf[4] == ' ' && buf[12] == '('
&& buf[17] == ')' && buf[22] == '/') {
i = bytedec(&buf[2]);
strcpy(libtno[i-1],&buf[28]);
}
}
if(isdigit(buf[2]) && buf[3] == ' ' /* 情報サービスチェック */
&& buf[4] == ' ' && buf[5] == ' '
&& buf[6] != ' ' && buf[strlen(buf)-1] == ')') {
xp = xftell();
if(!xfgets(buf3,81)) return(-2);
i = rtncut(buf3);
if(strlen(buf3) > 2 && buf3[2] != ' ') {
xfseek(xp);
return(0);
}
if(i) p_linecount++;
if(headcheck(NINFO) || setpoint3(NINFO,buf))
return(-1);
return(1);
}
return(0);
}
long sp = 0;
long splno = 0;
int passflag = 0;
void hpread(long count,int mode) /* タイトルテーブル作成メイン */
{
char buf[81],*buf2,buf3[91],bufwork[81];
long pp=0,pplno=0,xp,xplno,wp,max=0,wmax,l;
int no,i,j,smode=0;
PCELL far *pt;
long savexp,savexplno;
if(pend == 2) return;
if(mode == 1 || mode == 2) {
max = filelength(fileno(fd));
sprintf(buf,"ログファイル読み込み処理中(%ldByte)",max);
grh_disp(buf,0);
}
if(!pend && mode != 2 && (tagmode >= 3) && !nifoutropen()) {
if(!(midokumode & 1)) {
wmax = filelength(fileno(nifoutfd));
for(l=0;;) {
if(nifoutget()) break;
if(mode == 1) {
wp = ftell(nifoutfd);
if(++l > 20) {
grh_sub(wp,wmax);
l = 0;
}
}
}
nifoutclose(0);
for(pt=p_top,i=1;pt;pt=pt->next,i++) {
if(pt->flag & FTAG) tagno++;
pt->count = i;
}
tbl_set(p_tail);
xp = p_tail->p->tail;
xfseek(xp);
if(!xp || xfeof()) {
pend = 2;
return;
}
if(p_tail->mode == NEND) {
pt = p_tail;
p_tail = pt->back;
p_tail->next = 0;
p--;
i--;
tbl_free(pt);
}
tbl_set(p_tail);
xfseek(p_tail->p->top);
for(l=0,pp=xftell();;) {
if(lineread(buf)) break;
if(xftell() >= xp) break;
l++;
pp=xftell();
}
xfseek(pp);
p_linecount = pplno = p_tail->p->lineno + l;
count -= i-1;
jumpon = 0;
jpp = pp;
jpplno = pplno;
preno = p_tail->p->id;
forum3msgp = 0;
saveheya[0] = 'X';
nmode = p_tail->mode;
switch(nmode) {
case NMAIL:
case NMWRITE:
case NMRCV:
case NSDL:
case NRCL: forumon = 2;
nmode = NMAIL; break;
case NHPWRITE:
case NHPHEAD:
case NTITLE:
case NGUEST: nmode = NHP; break;
case NFORUM:
case NFWRITE:
case NMESHEAD:
case NFORUMHEAD:
case NFORUM2:
case NPGUEST: forumon = 1;
nmode = NFORUM; break;
case NLIBHEAD: nmode = NLIBNO; break;
case NPATIOHEAD: nmode = NPATIO; break;
}
}
else {
nifoutclose(0);
}
}
pend = 1;
if(sp) {
xfseek(sp);
strcpy(buf,savebuf);
pp = savepp;
pplno = savepplno;
p_linecount = splno;
}
else buf[0] = 0;
titlecountr = count;
for(l=0;p < MAXPOINT-1;) {
if(!titlecountr)
return;
if(mode == 3 && keycheck())
if(keycheck())
return;
xxstrncpy(savebuf,buf,80);
savepp = pp;
pp = xftell();
savepplno = pplno;
pplno = p_linecount;
if(lineread(buf)) goto hpend;
p_linecount++;
splno = p_linecount;
sp = xftell();
if(mode == 1 || mode == 2) {
if(++l > 200) {
grh_sub(pp,max);
l = 0;
}
}
if(strlen(buf) < 3) continue;
hpread_top:
if((i = jumpcheck(buf))) {
passflag = 0;
if(!jumpon) {
jumpon = 1;
jpp = pp;
jpplno = pplno;
if(i != 3) continue;
}
else {
if(i == 2 && !stagecheck(buf)) {
jpp = pp;
jpplno = pplno;
}
}
}
xxp = pp;
xxplno = pplno;
if((!passflag || passmode) && (smode = stagecheck(buf))) {
if(smode != NFORUM) forum3msgp = 0;
xp = pp;
xplno = pplno;
if(jumpon) {
xp = jpp;
xplno = jpplno;
jumpon = 0;
}
else if(nmode == smode && submode != SGUEST && submode != STITLE)
continue;
xxp = xp;
xxplno = xplno;
if(smode == NM2WRITE) {
if(lineread(buf3)) goto hpend;
p_linecount++;
smode = NMWRITE;
}
if(smode == NHPWRITE || smode == NFWRITE
|| smode == NMWRITE || smode == NWRITE) {
wp = xftell();
strcpy(buf,writetitle);
if(lineread(buf3)) goto hpend;
if(smode == NMWRITE) {
if(headcheck(NMAIL)) break;
xxp = pp;
xxplno = pplno;
strcat(buf3," ");
strncat80(buf,buf3);
if(lineread(buf3)) goto hpend;
}
xfseek(wp);
strncat80(buf,buf3);
/* savexp = xxp;
savexplno = xxplno;
xxp = xp;
xxplno = xplno; */
if(setpoint3(smode,buf)) break;
/* xxp = savexp;
xxplno = savexplno; */
/* nmode = smode; */
if((buf2=strstr(buf,"TO:")) && (strlen(&buf2[3]) >= 8))
nifidsetsub(&buf2[3]);
}
else if(smode == NPGUEST) {
if(setpoint3(NPGUEST,guesttitle)) break;
nmode = NFORUM;
}
else {
if(submode == SGUEST) {
if(!p_tail || (p_tail->mode != NHPHEAD && strlen(hpid))) {
gp = p;
if(hpout()) break;
xxp = pp;
xxplno = pplno;
}
if(setpoint3(NGUEST,guesttitle)) break;
nmode = NHP;
submode = 0;
}
else if(submode == STITLE) {
if(!p_tail || (p_tail->mode != NHPHEAD && strlen(hpid))) {
gp = p;
if(hpout()) break;
xxp = pp;
xxplno = pplno;
}
if(setpoint3(NTITLE,titlehptitle)) break;
nmode = NHP;
}
else {
gp = p;
if(stageset(smode,xp,xplno)) break;
switch(smode) {
case NMRCV:
case NSDL:
case NRCL:
smode = NMAIL;
}
nmode = smode;
if(jumpcheck(buf))
goto hpread_top;
}
}
continue;
}
if(submode == SPROF) {
strcpy(buf,"## 会員情報 ## :");
strncat(buf,profid,8);
if(setpoint2(NPROF,buf)) break;
nmode = NPROF;
nifidsetsub(profid);
submode = 0;
continue;
}
if((isdigit(buf[0]) && isdigit(buf[1]) /* 会議室チェック */
&& isdigit(buf[2])) && ((!xstrncmp(&buf[18]," ")
&& buf[3] == '/' && !xstrncmp(&buf[7]," "))
|| (!xstrncmp(&buf[11]," ") && buf[5] == '/'
&& !xstrncmp(&buf[20]," ")))) {
no = asctodec(buf);
memset(buf3,0,91);
if(!xfgets(buf3,81)) goto hpend;
if(rtncut(buf3))
p_linecount++;
if(*buf3 != '(') continue;
if(titlemode) {
if(buf[3] == '/') {
memset(bufwork,0,81);
strncpy(bufwork,buf,3);
strncat(bufwork,&buf3[6],9);
strncat80(bufwork,&buf[9]);
}
else {
memset(bufwork,0,81);
strncpy(bufwork,buf,5);
strncat(bufwork,&buf3[6],9);
strncat80(bufwork,&buf[11]);
}
}
else strcpy(bufwork,buf);
memcpy(heya,&buf3[1],2);
if(headcheck(NFORUM)) goto hpend;
if(!strncmp(savebuf,"- ",2) && savebuf[2] != 'M') {
if(!strlen(forumname) || !strstr(savebuf,forumname)) {
saveheya[0] = 0;
for(i=2,j=0;savebuf[i] != ' ' && j < 8;i++,j++)
forumname[j] = savebuf[i];
forumname[j] = 0;
}
}
if((saveheya[0] != 'X' && strncmp(saveheya,heya,2)) ||
(p_tail && p_tail->mode != NFORUM && p_tail->mode != NMESHEAD)) {
if(i = bytedec(&heya[0]))
fmeslibno = i;
gp = p;
if(heyasepa()) break;
preno = 0;
}
if(preno && no != preno + 1 && no != preno - 1) {
if(setpoint3(NSEPA,spalate)) break;
}
memcpy(saveheya,heya,2);
preno = no;
if(setpoint3(NFORUM,bufwork)) break;
if(buf[3] == '/') {
nifidsetsub(&buf[10]);
}
else {
nifidsetsub(&buf[12]);
p_tail->flag |= FCYCLE;
}
tbl_set(p_tail);
p_tail->p->id = no;
if(isdigit(buf3[50])) no = asctodec(&buf3[50]);
else if(isdigit(buf3[52])) no = asctodec(&buf3[52]);
else if(isdigit(buf3[54])) no = asctodec(&buf3[54]);
else no = 0;
p_tail->p->cno = no;
if(isdigit(buf3[23])) no = asctodec(&buf3[23]);
else if(isdigit(buf3[35])) no = asctodec(&buf3[35]);
else no = 0;
p_tail->p->cid = no;
passflag = 1;
continue;
}
if(submode != STITLE && isdigit(buf[0]) /* HPチェック */
&& isdigit(buf[1]) && isdigit(buf[2])
&& !xstrncmp(&buf[3]," [") && buf[8] == '/') {
if(headcheck(NHP)) goto hpend;
no = asctodec(buf);
if(nmode == NHP && preno && no != preno + 1)
if(setpoint3(NSEPA,spalate)) break;
preno = no;
if(setpoint3(NHP,buf)) break;
nifidsetsub(&buf[23]);
tbl_set(p_tail);
p_tail->p->id = no;
passflag = 1;
continue;
}
no = checkhpsub(buf);
if(no == -2) goto hpend;
if(no == -1) break;
if(no == 2) {
preno = 0;
continue;
}
if(++linecount > MAXLINE) {
if(stageset(nmode,xxp,xxplno)) break;
linecount = 1;
}
continue;
hpend:
if(mode == 1 || mode == 2)
grh_sub(max,max);
if(startmode < 8) break;
if(fno++ >= maxfno) break;
tbl_set(p_tail);
if(!p_tail->p->tail)
p_tail->p->tail = pp;
xfclose();
if(maxfno > 1) _fstrcpy((char far *)filename,file[fno-1]);
xfopen(filename);
cfno = fno;
nmode = 0;
topdisp();
if(mode == 1 || mode == 2) {
loc(39+1,line-1);iro(ILINE);
sprintf(buf,"%3d",fno);
print(buf);
deforutoiro();
max = filelength(fileno(fd));
sprintf(buf,"ログファイル読み込み処理中(%ldByte)",max);
grh_disp(buf,0);
l = 0;
}
}
if(p) {
tbl_free(rsv_p);
rsv_p = (PCELL far *)0;
xxp = pp;
xxplno = p_linecount;
setpoint2(NEND,dataend);
pend=2;
}
}
static int logstrcat(char *a,char *b)
{
int i,j;
if(!strlen(b)) return(0);
for(i=j=0;b[i];i++) {
/* if(b[i] <= ' ' || b[i] >= 0x7f)
return(0);
a[j++] = b[i]; */
if(b[i] >= ' ')
a[j++] = b[i];
}
a[j] = 0;
return(j);
}
char logforum[9],loghpid[9],logmes[3],loglib[3],logniftyid[9];
static FILE *logfd;
static char dirbuf[128];
static char savedirbuf[128]="";
static char save2dirbuf[128]="";
static char dirbuf1[140];
static char logfmode;
static int logsavemode,log2mode,datk;
static int logputsub(char *path)
{
char fname[53],buf[81];
if(log2mode)
return(0);
sprintf(buf, "出力失敗.切り換え先ファイル名 = ");
fname[0] = 50;
strcpy(&fname[2],path);
cgetfsx(buf, fname);
if(!fname[2])
return(0);
strcpy(path,&fname[2]);
return(1);
}
static int logopen(int mode)
{
char buf[140],*w,work[81],*o,*p;
int i,j,k;
long ep=0;
if(mode != -1) {
if(!logdir[mode]) {
logclose(1);
return(-1);
}
logsavemode = mode;
_fstrcpy((char far *)buf,logdir[mode]);
for(i=j=0;buf[i];i++) {
if(iskanji(buf[i]) && iskanji2(buf[i+1])) {
dirbuf[j++] = buf[i++];
dirbuf[j++] = buf[i];
continue;
}
if(buf[i] == '%') {
o = &buf[i+1];
if(p = jstrchr(o,'%')) {
*p++ = 0;
strcpy(work,o);
strupr(work);
i += strlen(o) + 1;
if(o = getenv(work)) {
strcpy(&dirbuf[j],o);
j += strlen(o);
}
continue;
}
}
if(buf[i] == '$') {
switch(buf[++i]) {
case 'f': k = logstrcat(&dirbuf[j],logforum);
break;
case 'h': k = logstrcat(&dirbuf[j],loghpid);
break;
case 'i': k = logstrcat(&dirbuf[j],logniftyid);
break;
case 'm': k = logstrcat(&dirbuf[j],logmes);
break;
case 'l': k = logstrcat(&dirbuf[j],loglib);
break;
case 'y': k = logstrcat(&dirbuf[j],YEAR);
break;
case 'Y': k = logstrcat(&dirbuf[j],year);
break;
case 'T': k = logstrcat(&dirbuf[j],mon);
break;
case 'D': k = logstrcat(&dirbuf[j],mday);
break;
case 'H': k = logstrcat(&dirbuf[j],hour1);
break;
case 'J': k = logstrcat(&dirbuf[j],hour2);
break;
case 'M': k = logstrcat(&dirbuf[j],min);
break;
case 'S': k = logstrcat(&dirbuf[j],sec);
break;
case 'P': k = logstrcat(&dirbuf[j],ampm);
break;
case 'a': k = logstrcat(&dirbuf[j],mon2);
break;
default: dirbuf[j] = buf[i]; k = 1; break;
}
j += k;
continue;
}
if(buf[i] <= ' ' || buf[i] == 0x7f) continue;
dirbuf[j++] = buf[i];
}
dirbuf[j] = 0;
}
if(!strlen(dirbuf)) {
logclose(1);
return(-1);
}
if(!strcmp(dirbuf,savedirbuf))
return(0);
if(strlen(save2dirbuf) && !strcmp(dirbuf,save2dirbuf))
return(0);
logclose(1);
save2dirbuf[0] = 0;
while(1) {
logfd = fopen_sub(dirbuf,0);
if(!logfd) {
if(!strlen(save2dirbuf)) strcpy(save2dirbuf,dirbuf);
if(!logputsub(dirbuf)) {
save2dirbuf[0] = 0;
return(-1);
}
}
else break;
}
logfmode = 1;
strcpy(savedirbuf,dirbuf);
if((tagmode == 1 || tagmode ==2) && !log2mode) {
get_fdir(dirbuf,dirbuf1);
for(i=0,datk=-1;datf[i];i++) {
_fstrcpy((char far *)buf,datf[i]);
if(!(w=jstrchr(buf,' '))) break;
*w = 0;
if(strcmp(buf,dirbuf1)) continue;
w++;
if(w[0] == '@') ep = atol(&w[1]);
else {
logfmode = 0;
ep = atol(w);
}
datk = i;
break;
}
midokuno = ep;
}
return(0);
}
static int logeditsub(PCELL far *tcu)
{
char buf[81];
int k,m;
if(!logfd)
return(0);
tbl_set(tcu);
if(tcu->p->top == tcu->p->tail)
return(0);
if((tagmode ==1 || tagmode == 2) && !log2mode
&& logfmode && (tcu->mode < NHPHEAD)) {
if(!(tcu->flag & FYOMI))
logfmode = 0;
else midokuno++;
}
loged_01:
if(m = bunget(tcu,0)) {
for(k=0;k < m-1;k++) {
_fstrcpy((char far *)buf,buf1[k]);
farfree(buf1[k]);
buf1[k] = 0;
if(fputs(buf,logfd) == EOF) {
for(;buf1[k] && k < MAXLINE;k++) {
farfree(buf1[k]);
buf1[k] = 0;
}
logclose(1);
if(logputsub(dirbuf)) {
if(!logopen(-1))
goto loged_01;
}
return(-1);
}
}
}
return(0);
}
void logclose(int mode) /* mode = 0:疑似クローズ 1:強制クローズ */
{
char buf[150],fname[129],*a;
int fid;
struct tm *jtime;
time_t ltime[1];
struct ftime ftime;
if(!mode) return;
if(!logfd)
return;
if((tagmode == 1 || tagmode == 2) && !log2mode) {
if(datk != -1) {
farfree(datf[datk]);
datf[datk] = 0;
}
else {
for(datk=0;datf[datk];datk++)
;
}
if(midokuno) {
if(logfmode) sprintf(buf,"%s @%d",dirbuf1,midokuno);
else sprintf(buf,"%s %d",dirbuf1,midokuno);
if(datf[datk]=farmalloc(strlen(buf)+1))
_fstrcpy(datf[datk],(char far *)buf);
else errdisp1(memgeterror);
}
}
if(tagmode >= 3) {
get_fdir(savedirbuf,fname); /* フルパス名取得 */
strcpy(buf,datfile);
if(strlen(buf)) {
if(!(a = jstrrchr(fname,'\\'))) {
strcat(buf,fname);
}
else {
strcat(buf,++a);
}
}
else strcpy(buf,fname);
if((a = jstrrchr(buf,'.')))
*a = 0;
strcat(buf,".");
strcat(buf,nifsafix);
time(ltime);
jtime = localtime(ltime);
ftime.ft_year = jtime->tm_year-80;
ftime.ft_month = jtime->tm_mon+1;
ftime.ft_day = jtime->tm_mday;
ftime.ft_hour = jtime->tm_hour;
ftime.ft_min = jtime->tm_min;
ftime.ft_tsec = jtime->tm_sec & 0xfe;
fid = open(buf,O_RDWR,S_IREAD | S_IWRITE);
if(fid) {
setftime(fid,&ftime);
close(fid);
}
}
fclose(logfd);
logfd = (FILE *)0;
savedirbuf[0] = 0;
}
static int logfputs(char *buf)
{
strcat(buf,"\n");
while(1) {
if(fputs(buf,logfd) != EOF)
return(0);
logclose(1);
if(logputsub(dirbuf)) {
if(!logopen(-1))
continue;
}
break;
}
return(-1);
}
void xstrncpy(char *a,char *b)
{
int i,j;
for(i=0;b[i] && b[i] <= ' ';i++)
;
for(j=0;b[i] && b[i] > ' ' && i < 8;i++)
a[j++] = b[i];
a[j] = 0;
}
int logedit1(PCELL far *pt,int mode,int mode2) /* ログ整理 */
{
char buf[90],*a;
int m;
log2mode = mode;
if(mode2) mode2 = LETC+1;
tbl_set(pt);
_fstrcpy((char far *)buf,pt->p->title);
switch(pt->mode) {
case NHP: m = LHP;
break;
case NMAIL: m = LMAIL;
break;
case NFORUM: m = LFORUM;
break;
case NNEWS: m = LNEWS;
break;
case NBBS: m = LBBS;
break;
case NNOTE: m = LNOTE;
break;
case NSINBUN: m = LSINBUN;
break;
case NHPWRITE: m = LHPWRITE;
break;
case NFWRITE: m = LFWRITE;
break;
case NGUEST: m = LGUEST;
break;
case NLIBDATA: m = LLIBDATA;
break;
case NFNEWS: m = LFNEWS;
break;
case NFBBS: m = LFBBS;
break;
case NMWRITE: m = LMWRITE;
break;
case NWRITE: m = LWRITE;
break;
case NPROF: m = LPROF;
break;
case NINFO: m = LINFO;
break;
case NTENKI: m = LTENKI;
break;
case NHPHEAD:
if(pt->next->mode != NHP && pt->next->mode != NTITLE)
return(0);
_fstrcpy((char far *)loghpid,pt->p->nifid);
m = LHPHEAD;
goto loged_01;
case NMAILHEAD:
m = LMAILHEAD;
loged_00: _fstrcpy((char far *)logniftyid,pt->p->nifid);
break;
case NFORUMHEAD:
case NFORUM2:
_fstrcpy((char far *)logforum,pt->p->nifid);
m = LFORUMHEAD;
break;
case NNEWSHEAD: m = LNEWSHEAD;
break;
case NBBSHEAD: m = LBBSHEAD;
break;
case NCBHEAD: m = LCBHEAD;
break;
case NNOTEHEAD: m = LNOTEHEAD;
break;
case NBILLHEAD:
m = LBILLHEAD;
goto loged_00;
case NBYEHEAD:
m = LBYEHEAD;
goto loged_00;
case NSINBUNHEAD: m = LSINBUNHEAD;
break;
case NLIBHEAD:
_fstrcpy((char far *)logforum,pt->p->nifid);
sprintf(loglib,"%02d",pt->p->cno);
m = LLIBHEAD;
loged_03: if(logopen(m+mode2)) return(-1);
if(logfputs(buf)) return(-1);
if(logeditsub(pt)) return(-1);
logclose(0);
return(0);
case NMESHEAD:
_fstrcpy((char far *)logforum,pt->p->nifid);
sprintf(logmes,"%02d",pt->p->cno);
if(pt->next->mode != NFORUM)
return(0);
m = LMESHEAD;
loged_01: if(logopen(m+mode2)) return(-1);
if(logfputs(buf)) return(-1);
logclose(0);
return(0);
case NFRTHEAD: m = LFRTHEAD;
loged_02: _fstrcpy((char far *)logforum,pt->p->nifid);
goto loged_03;
case NFRSHEAD: m = LFRSHEAD;
goto loged_02;
case NFRTIMEHEAD: m = LFRTIMEHEAD;
goto loged_02;
case NOPTHEAD: m = LOPTHEAD;
goto loged_02;
case NFNEWSHEAD: m = LFNEWSHEAD;
goto loged_02;
case NFBBSHEAD: m = LFBBSHEAD;
goto loged_02;
case NLIBNOHEAD: m = LLIBNOHEAD;
goto loged_02;
case NMESNOHEAD: m = LMESNOHEAD;
goto loged_02;
case NMEMBERHEAD: m = LMEMBERHEAD;
break;
case NINFOHEAD: m = NINFOHEAD;
break;
case NMRCVHEAD: m = LMRCVHEAD;
break;
case NSDLHEAD: m = LSDLHEAD;
break;
case NRCLHEAD: m = LRCLHEAD;
break;
case NTITLE: m = LTITLE;
break;
case NINIT: m = LINIT;
goto loged_00;
case NTOP: m = LTOP;
break;
case NMYFORUM: m = LMYFORUM;
break;
case NPATIOHEAD: _fstrcpy((char far *)logforum,pt->p->nifid);
m = LPATIOHEAD;
break;
case NPGUEST: m = LPGUEST;
break;
default: m = LETC;
break;
}
if(logopen(m+mode2)) return(-1);
if(logeditsub(pt)) return(-1);
logclose(0);
return(0);
}
static char *nifoutsub(char *buf) {
char *o;
o = jstrchr(buf,',');
if(o) *o++ = 0;
return(o);
}
static long nifouthex(char *buf) {
long l,i;
char c;
for(l=0;c = *buf;buf++) {
if(c >= '0' && c <= '9') i=c-'0';
else i=c-'a'+10;
l = l*16 + i;
}
return(l);
}
int nifoutropen(void) {
char fname[129],*a,buf[150];
struct stat sbuf,sbuf2;
get_fdir(filename,fname); /* フルパス名取得 */
strcpy(nifoutfname,datfile);
if(strlen(nifoutfname)) {
if(!(a = jstrrchr(fname,'\\'))) {
strcat(nifoutfname,fname);
}
else {
strcat(nifoutfname,++a);
}
}
else strcpy(nifoutfname,fname);
strcpy(buf,fname);
strcat(buf,"\n");
if((a = jstrrchr(nifoutfname,'.')))
*a = 0;
strcpy(nifoutfname2,nifoutfname);
strcat(nifoutfname,".");
strcat(nifoutfname,nifsafix);
strcat(nifoutfname2,".###");
strcpy(nifoutfname1,fname);
if(stat(filename,&sbuf) || stat(nifoutfname,&sbuf2))
return(-1);
if(timechkmode && (sbuf.st_atime > sbuf2.st_atime))
return(-1);
nifoutfd = fopen(nifoutfname,"rt");
if(!nifoutfd)
return(-1);
for(;;) {
if(fgets(buf,150,nifoutfd) == NULL) break;
rtncut(buf);
if(!strcmp(buf,nifoutfname1)) return(0);
for(;;) {
if(fgets(buf,150,nifoutfd) == NULL) return(-1);
nifoutsub(buf);
if(nifouthex(buf) == NEND) break;
}
}
return(-1);
}
int nifoutopen(void) {
char buf[150];
remove(nifoutfname2);
if(!(nifoutfd2 = fopen(nifoutfname2,"at"))) {
errdisp2("XXXX.NIFファイルのオープンに失敗");
return(-1);
}
if(nifoutfd = fopen(nifoutfname,"rt")) {
for(;;) {
if(fgets(buf,150,nifoutfd) == NULL) break;
if(fputs(buf,nifoutfd2) == EOF) {
goto nifouto_err;
}
rtncut(buf);
if(!strcmp(buf,nifoutfname1)) {
for(;;) {
if(fgets(buf,150,nifoutfd) == NULL) return(0);
nifoutsub(buf);
if(nifouthex(buf) == NEND) break;
}
return(0);
}
for(;;) {
if(!fgets(buf,150,nifoutfd)) return(0);
if(fputs(buf,nifoutfd2) == EOF) {
goto nifouto_err;
}
nifoutsub(buf);
if(nifouthex(buf) == NEND) break;
}
}
}
strcpy(buf,nifoutfname1);
strcat(buf,"\n");
if(fputs(buf,nifoutfd2) == EOF) {
nifouto_err:
errdisp2("XXXX.NIFファイルの書き込みに失敗");
fclose(nifoutfd);
fclose(nifoutfd2);
return(-1);
}
return(0);
}
int nifoutput(PCELL far *pt) {
char buf[150],work[128],nifid[9],title[81];
int count,flag;
flag = (int)pt->flag;
flag &= (FYOMI + FTAG +FCYCLE);
count = pt->grp->count;
memset(nifid,0,9);
tbl_set(pt);
_fmemcpy((char far *)nifid,pt->p->nifid,8);
_fstrcpy((char far *)title,pt->p->title);
sprintf(buf,"%x,%x,%x,%lx,",
pt->mode,flag,pt->count,pt->p->top);
sprintf(work,"%lx,",pt->p->tail);
strcat(buf,work);
sprintf(work,"%x,",count);
strcat(buf,work);
sprintf(work,"%x,-%lx,%s,%x,%x,%x,%s\n",
pt->p->cmt,pt->p->lineno,nifid,pt->p->id,pt->p->cno,pt->p->cid,title);
strcat(buf,work);
if(nifoutfd2) {
if(fputs(buf,nifoutfd2) == EOF) {
errdisp2("XXXX.NIFファイルの書き込みに失敗");
return(-1);
}
}
return(0);
}
int nifoutget(void) {
char buf[150],*o,*s;
int grp,i,j;
PCELL far *pt;
PCELL far *pt2;
PCELL far *w;
if(!fgets(buf,150,nifoutfd)) return(1);
rtncut(buf);
pt = tbl_alloc(0);
if(!pt) {
errdisp3(memgeterror);
return(-1);
}
o=nifoutsub(buf);
pt->mode = (char)nifouthex(buf);
s = o;
o=nifoutsub(s);
pt->flag = (char)nifouthex(s);
s = o;
o=nifoutsub(s);
pt->count = (int)nifouthex(s);
tbl_set(pt);
pt->p->fno = fno;
s = o;
o=nifoutsub(s);
pt->p->top = nifouthex(s);
s = o;
o=nifoutsub(s);
pt->p->tail = nifouthex(s);
s = o;
o=nifoutsub(s);
grp = (int)nifouthex(s);
if(pt->count == grp) pt->grp = pt;
else {
for(w=p_tail;w;w=w->back) {
if(w->count != grp) continue;
pt->grp = w;
break;
}
if(!w) pt->grp = pt;
}
s = o;
o=nifoutsub(s);
pt->p->cmt = (int)nifouthex(s);
s = o;
o=nifoutsub(s);
if(*s == '-') {
pt->p->lineno = nifouthex(s+1);
s = o;
o=nifoutsub(s);
}
else pt->p->lineno = 0;
_fstrncpy(pt->p->nifid,(char far *)s,8);
s = o;
o=nifoutsub(s);
pt->p->id = (int)nifouthex(s);
s = o;
o=nifoutsub(s);
pt->p->cno = (int)nifouthex(s);
s = o;
o=nifoutsub(s);
pt->p->cid = (int)nifouthex(s);
_fstrcpy(pt->p->title,(char far *)o);
if(!p_tail) {
p_top = p_head = p_tail = pt;
}
else {
if(p_tail->mode == NFORUM || p_tail->mode == NHP) {
tbl_set(p_tail);
i = p_tail->p->id;
tbl_set(pt);
j = pt->p->id;
if(i && j && j != i+1 && j != i-1) {
if((pt2=cmtsepa(pt->grp)) != (PCELL far *)-1) {
p_tail->next = pt2;
pt2->back = p_tail;
p_tail = pt2;
p++;
}
}
}
p_tail->next = pt;
pt->back = p_tail;
p_tail = pt;
}
p++;
if(pt->mode == NEND) return(1);
return(0);
}
void nifoutclose(int mode) {
char buf[150];
if(mode) {
for(;;) {
if(!nifoutfd || fgets(buf,150,nifoutfd) == NULL) break;
if(fputs(buf,nifoutfd2) == EOF) {
errdisp2("XXXX.NIFファイルの書き込みに失敗");
break;
}
}
if(nifoutfd) {
fclose(nifoutfd);
remove(nifoutfname);
}
if(nifoutfd2) {
fclose(nifoutfd2);
rename(nifoutfname2,nifoutfname);
}
}
else {
if(nifoutfd) fclose(nifoutfd);
}
}